# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=gitui
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.27.0
pkgrel=1
pkgdesc='Blazing fast terminal-ui for git written in Rust (mingw-w64)'
msys2_references=(
  'anitya: 187553'
  'archlinux: gitui'
  'purl: pkg:cargo/gitui'
)
url='https://github.com/extrawurst/gitui'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-libssh2"
         "${MINGW_PACKAGE_PREFIX}-libgit2")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-openssl"
             'git')
checkdepends=("${MINGW_PACKAGE_PREFIX}-python")
source=("git+https://github.com/extrawurst/gitui.git#tag=v${pkgver}")
sha256sums=('4f38937ac63456fbd854b865c520996d834ee9014a9ad0ad1b04382eec785a34')

_env() {
  export OPENSSL_NO_VENDOR=1
  export LIBGIT2_NO_VENDOR=1
  export PKG_CONFIG_ALL_DYNAMIC=1
  export LIBSSH2_SYS_USE_PKG_CONFIG=1
  export GITUI_RELEASE=1
}

prepare() {
  cd "${_realname}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}"

  _env
  cargo build \
    --frozen \
    --release \
    --no-default-features \
    --features "ghemoji regex-fancy trace-libgit"
}

check() {
  cd "${_realname}"

  _env
  cargo test \
    --frozen \
    --release \
    --no-default-features \
    --features "ghemoji regex-fancy trace-libgit"
}

package() {
  cd "${_realname}"

  _env
  cargo install \
    --frozen \
    --offline \
    --no-track \
    --no-default-features \
    --features "ghemoji regex-fancy trace-libgit" \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 {KEY_CONFIG,THEMES}.md -t "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  install -Dm644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md"
}
